package com.echo.code.spring.tx;

import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Description
 *
 * @author baiyp
 * @version 1.0.0
 * @date 2019/04/14
 */
public class DaoClient {

  public static void main(String[] args) throws SQLException {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
    BasicDataSource dataSource = context.getBean("dataSource", BasicDataSource.class);
    Connection connection = dataSource.getConnection();
    DatabaseMetaData metaData = connection.getMetaData();
    System.out.println("supportsTransactions: " + metaData.supportsTransactions());
    System.out.println("supportsSavepoints: " + metaData.supportsSavepoints());
    connection.close();
    List<User> list = new ArrayList<>(2);
    list.add(User.builder().name("aa").phone("88888").address("BJ").build());
    list.add(User.builder().name("bb").phone("00000").address("SH").build());
    UserService userService = context.getBean(UserService.class);
    userService.addUser(list);
    context.close();
  }
}
